package com.hyy.controller;

import com.hyy.bean.MaskUser;
import com.hyy.bean.Merchandise;
import com.hyy.service.CartService;
import com.hyy.service.serviceImpl.CartServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@WebServlet(name = "MycartServlet",urlPatterns = "/myCart")
public class MycartServlet extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		this.doPost(req,resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		MaskUser user = (MaskUser) req.getSession().getAttribute("user");
		CartService cartService = new CartServiceImpl();
		Map<Merchandise,Long> cartMerchandises = cartService.showAllByUid(user.getUserid());
		req.setAttribute("cartMerchandises",cartMerchandises);
		req.getRequestDispatcher("/jsp/cart.jsp").forward(req,resp);
	}
}
